package cn.daniellee.plugin.rs.command;

import cn.daniellee.plugin.rs.core.ShopCore;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ShopCompleter implements TabCompleter {

	@Override
	public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
		if (strings.length == 1) {
			List<String> commands = new ArrayList<>();
			commands.add("list");
			commands.add("reset");
			commands.add("reload");
			commands.addAll(Collections.list(ShopCore.SHOPS.keys()));
			return commands;
		} else if (strings.length == 2 && "reset".equalsIgnoreCase(strings[0])) {
			return Bukkit.getOnlinePlayers().stream().map(Player::getName).toList();
		} else if (strings.length == 3 && "reset".equalsIgnoreCase(strings[0])) {
			return Collections.list(ShopCore.SHOPS.keys());
		}
		return new ArrayList<>();
	}

}
